package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Student;


public class StudentDao implements BaseStudentDao{
    private static Student[] students = new Student[5];

    public boolean addStudent(Student stu) {
        int index = -1;
        for (int i = 0; i < students.length; i++) {
            Student student = students[i];
            if (student == null) {
                index = i;
                break;
            }
        }
        if (index == (-1)) {
            return false;
        } else {
            students[index] = stu;
            return true;
        }
    }

    public Student[] findAllStudents() {
        return students;
    }

    public void deleteStudentById(String id) {
        for (int i = 0; i < students.length; i++) {
            Student s = students[i];
            if (s != null && s.getId().equals(id)) {
                students[i] = null;
                break;
            }
        }
    }

    public void updateStudentById(Student stu) {
        String id=stu.getId();
        for (int i = 0; i < students.length; i++) {
            Student s = students[i];
            if (s!=null&&s.getId().equals(id)){
                students[i]=stu;
                break;
            }
        }
    }
}
